<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="org.apache.shiro.SecurityUtils" %>
<%@ page import="com.topisv.tms.service.account.ShiroDbRealm.ShiroUser" %>

<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
<script type="text/javascript">
  
  
  var dataTables_unhandle;  //dataTables-待处理订单 
  var dataTables_working;   //dataTables-作业中订单 
  var dataTables_handled;   //dataTables-已发货订单 
  var dataTables_exception; //dataTables-异常订单 
  var dataTables_sendOutFail; //dataTables-订单回传失败
  
  
  $(function() {
		$("#queryForm").validate(); 
		$("#add").hide();
		
		//初始化日期选择框
		var now = new Date();
		var today=(now.getFullYear())+"/"+(now.getMonth()<10? "0"+(now.getMonth()+1):(now.getMonth()+1))+"/"+(now.getDate()<10? "0"+now.getDate():now.getDate());    
		$("#_dataRange").val(today+"-"+today);
		$("#_dataRange").daterangepicker({format: 'YYYY/MM/DD',dateLimit :{days : 31}});
	});

    //初始化dataTables-待处理订单
    function initTableUnhandle(){
	    dataTables_unhandle=$("#table_unhandle").dataTable({
           "bServerSide":true,
           "sAjaxSource":'${ctx}/v2/firstPage/bindData_unhandle',
           "fnServerData": retrieveData_unhandle,
           
           "iDisplayLength": 10, //每页数据
           "bPaginate": true, //翻页功能
           "bLengthChange": true, //改变每页显示数据数量
           "bFilter": false, //过滤功能
           "bSort": false, //排序功能
           "bInfo": true,//页脚信息
           "bAutoWidth": true,//自动宽度
           "bStateSave": false, //状态保存，使用了翻页或者改变了每页显示数据数量，会保存在cookie中，下回访问时会显示上一次关闭页面时的内容
           "bProcessing": true, //加载数据时显示正在加载信息
           
           "aoColumns": [  //排序控制
				null,
				{ "asSorting": [ "asc" ] },
				{ "asSorting": [ "desc", "asc", "asc" ] }
			],
           
           "sZeroRecords": "查询无记录！",
           "oLanguage": { //汉化   
               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
            },
            "aoColumns": [ 
                    {"mData": null,
                    	 "mRender": function (data, display, row) {
		              		<c:forEach items="${customerList}" var="customer">
								if("${customer.customerCode}" == row.customerCode){
									return "${customer.customerName}";
								}
							</c:forEach>
							return "";
			           }
                    },
                    {"mData": 'warehouseCode'}, 
                    {
                      "mData": 'ordeno',
                      "render":function(obj){
                        return "<a href='${ctx}/orderMsg/v2_orderMsgDetail/"+obj+"' title='查看订单信息' target='_blank'>"+obj+"</a>";
                      }	
                    },
                    {"mData": 'shopna'},
                    {"mData": 'recena'},
                    {"mData": 'provna'},
                    {"mData": 'cacode'},
                    {
                      "mData": 'dispatchFlag',
                      "render": function (obj) {
                         return "1" == obj ? "是" : "否";
                      }
                    },
                    {
                      "mData": 'crtime',
                      "render": function (obj) {
                         var time=obj.time;
                         var date = new Date(time);
                         return date.Format("MM-dd hh:mm");
                      }
                    },
                    {
                     "mData": 'addres',
                     "render": function (obj,type,full) {
                    	var ret ="";
                    	/**begin remove 20160713 by zhangweize**/
						/* if(full.dispatchFlag == "0"){
							ret = "<a href='#reuse' onclick='getAjaxReuse("+full.id+")' class='btn btn-default btn-sm' role='button' data-toggle='modal' >重接订单</a>";
						} else {
							ret = "<a href='#ordersDetail' onclick='getAjaxOrders("+full.id+")' class='btn btn-default btn-sm' role='button' data-toggle='modal' >订单详情</a>";
						}  */  
						/**end  remove 20160713 by zhangweize**/
						/**begin add 20160713 去掉重接按钮 by zhangweize**/
						ret = "<a href='#ordersDetail' onclick='getAjaxOrders("+full.id+")' class='btn btn-default btn-sm' role='button' data-toggle='modal' >订单详情</a>";
						/**begin add 20160713 去掉重接按钮 byzhangweize**/
                        return ret+" <a href='#orderItemsDetail' onclick='getAjaxItems("+full.id+")' class='btn btn-default btn-sm' role='button' data-toggle='modal' >商品详情</a>";
                      }
                    }
             ]
        });
    }
	
    //初始化dataTables-作业中
    function initTableWorking(){
      dataTables_working=$("#table_working").dataTable({
         "bServerSide":true,
         "sAjaxSource":'${ctx}/v2/firstPage/bindData_working',
         "fnServerData": retrieveData_working,
         "bFilter": false,
         "bSort": false,
         "sZeroRecords": "查询无记录！",
         "bProcessing": true,
         "oLanguage": {
             "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
          },
          "aoColumns": [ 
                  {"mData": null,
                  	 "mRender": function (data, display, row) {
	              		<c:forEach items="${customerList}" var="customer">
							if("${customer.customerCode}" == row.customerCode){
								return "${customer.customerName}";
							}
						</c:forEach>
						return "";
		           }
                  },
                  {
                    "mData": 'order',
                    "render":function(obj){
                      return "<a href='${ctx}/orderMsg/v2_orderMsgDetail/"+obj.ordeno+"' title='查看订单信息' target='_blank'>"+obj.ordeno+"</a>";
                    }
                  },
                  {"mData": 'customerOrderno'},
                  {"mData": 'fromno'},
                  {"mData": 'expressNo',
                   "render":function(obj,type,full){
                  	return full.expressNo||full.ebillNo;
                  }},
                  {
                    "mData": 'billType',
                    "render": function (obj) {
                       var billType=obj;
                       if(billType=='cbill'){
                         return "普通面单";
                       }else if(billType=='ebill'){
                         return "电子面单";
                       }else{
                         return "";
                       }
                    }
                  },
                  {"mData": 'warehouseCode'},
                  {"mData": 'batchCode',
                   "render":function(obj){
                          return "<a href='${ctx}/workMsg/v2_workMsgDetail/"+obj+"' title='查看批次信息' target='_blank'>"+obj+"</a>";
                    }
                  },
                  {"mData": 'taskCode',
                   "render":function(obj){
                          return "<a href='${ctx}/orderMsg/v2_queryOrderMsg?_taskCode="+obj+"' title='查看任务信息' target='_blank'>"+obj+"</a>";
                     }
                  },
                  {
                    "mData": 'cancelStatus',
                    "render": function (obj) {
                       var cancelStatus=obj;
                       if(cancelStatus=='ok'){
                         return "正常单";
                       }else if(cancelStatus=='cancel'){
                         return "<font color=red>取消单</font>";
                       }else if(cancelStatus=='refuse'){
                         return "<font color=red>拒收单</font>";
                       }else if(cancelStatus=='change'){
                         return "<font color=red>换货单</font>";
                       }else if(cancelStatus=='outScope'){
                         return "<font color=red>超区件</font>";
                       }else if(cancelStatus=='lose'){
                         return "<font color=red>丢件单</font>";
                       }else{
                         return "";
                       }
                    }
                  },
                  {
                    "mData": 'status',
                    "render": function (obj) {
                       var status=obj;
                       if(status=='1'){
                         return "创建批次";
                       }else if(status=='2'){
                         return "创建任务";
                       }else if(status=='3'){
                         return "已拣货";
                       }else if(status=='4'){
                         return "已灯光拣选";
                       }else if(status=='5'){
                         return "已包装";
                       }else if(status=='6'){
                         return "已发货";
                       }else if(status=='9'){
                         return "待包装";
                       }else if(status=='0'){
                         return "待创建批次";
                       }else{
                         return "";
                       }
                    }
                  }
           ]
      });
    }
     
    //初始化dataTables-已发货
    function initTableHandled(){
      dataTables_handled=$("#table_handled").dataTable({
         "bServerSide":true,
         "sAjaxSource":'${ctx}/v2/firstPage/bindData_handled',
         "fnServerData": retrieveData_handled,
         "bFilter": false,
         "bSort": false,
         "sZeroRecords": "查询无记录！",
         "bProcessing": true,
         "oLanguage": {
             "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
          },
          "aoColumns": [ 
                  {"mData": null,
                  	 "mRender": function (data, display, row) {
	              		<c:forEach items="${customerList}" var="customer">
							if("${customer.customerCode}" == row.customerCode){
								return "${customer.customerName}";
							}
						</c:forEach>
						return "";
		           }
                  },
                  {
                    "mData": 'order.ordeno',
                    "render":function(obj){
                      return "<a href='${ctx}/orderMsg/v2_orderMsgDetail/"+obj+"' title='查看订单信息' target='_blank'>"+obj+"</a>";
                    }
                  },
                  {"mData": 'customerOrderno'},
                  {"mData": 'order.shopna'},
                  {"mData": 'fromno'},
                  {"mData": 'expressNo',
                  "render":function(obj,type,full){
                  	return full.expressNo||full.ebillNo;
                  }},
                  {
                    "mData": 'billType',
                    "render": function (obj) {
                       var billType=obj;
                       if(billType=='cbill'){
                         return "普通面单";
                       }else if(billType=='ebill'){
                         return "电子面单";
                       }else{
                         return "";
                       }
                    }
                  },
                  {"mData": 'warehouseCode'},
                  {"mData": 'batchCode',
                   "render":function(obj){
                          return "<a href='${ctx}/workMsg/v2_workMsgDetail/"+obj+"' title='查看批次信息' target='_blank'>"+obj+"</a>";
                    }
                  },
                  {"mData": 'order.recena'},
                  {
                    "mData": 'cancelStatus',
                    "render": function (obj) {
                       var cancelStatus=obj;
                       if(cancelStatus=='ok'){
                         return "正常单";
                       }else if(cancelStatus=='cancel'){
                         return "<font color=red>取消单</font>";
                       }else if(cancelStatus=='refuse'){
                         return "<font color=red>拒收单</font>";
                       }else if(cancelStatus=='change'){
                         return "<font color=red>换货单</font>";
                       }else if(cancelStatus=='outScope'){
                         return "<font color=red>超区件</font>";
                       }else if(cancelStatus=='lose'){
                         return "<font color=red>丢件单</font>";
                       }else{
                         return "";
                       }
                    }
                  },
                  {
                    "mData": 'status',
                    "render": function (obj) {
                       var status=obj;
                       if(status=='1'){
                         return "创建批次";
                       }else if(status=='2'){
                         return "创建任务";
                       }else if(status=='3'){
                         return "已拣货";
                       }else if(status=='4'){
                         return "已灯光拣选";
                       }else if(status=='5'){
                         return "待包装";
                       }else if(status=='6'){
                         return "已发货";
                       }else if(status=='9'){
                         return "待包装";
                       }else if(status=='0'){
                         return "待创建批次";
                       }else{
                         return "";
                       }
                    }
                  }
           ]
      });
    }
    
    //初始化dataTables-异常单
    function initTableException(){
      dataTables_exception=$("#table_exception").dataTable({
         "bServerSide":true,
         "sAjaxSource":'${ctx}/v2/firstPage/bindData_exception',
         "fnServerData": retrieveData_exception,
         "bFilter": false,
         "bSort": false,
         "sZeroRecords": "查询无记录！",
         "bProcessing": true,
         "oLanguage": {
             "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
          },
          "aoColumns": [ 
                  {"mData": null,
                  	 "mRender": function (data, display, row) {
	              		<c:forEach items="${customerList}" var="customer">
							if("${customer.customerCode}" == row.customerCode){
								return "${customer.customerName}";
							}
						</c:forEach>
						return "";
		           }
                  },
                  {
                    "mData": 'order.ordeno',
                    "render":function(obj){
                      return "<a href='${ctx}/orderMsg/v2_orderMsgDetail/"+obj+"' title='查看订单信息' target='_blank'>"+obj+"</a>";
                    }
                  },
                  {
                    "mData": 'order.shopna',
                    "sDefaultContent": ""
                  },
                  {"mData": 'customerOrderno'},
                  {"mData": 'fromno'},
                  {"mData": 'expressNo',
                  "render":function(obj,type,full){
                  	return full.expressNo||full.ebillNo;
                  }},
                  {
                    "mData": 'billType',
                    "render": function (obj) {
                       var billType=obj;
                       if(billType=='cbill'){
                         return "普通面单";
                       }else if(billType=='ebill'){
                         return "电子面单";
                       }else{
                         return "";
                       }
                    }
                  },
                  {"mData": 'warehouseCode'},
                  {"mData": 'batchCode',
                   "render":function(obj){
                          return "<a href='${ctx}/workMsg/v2_workMsgDetail/"+obj+"' title='查看批次信息' target='_blank'>"+obj+"</a>";
                    }
                  },
                  {"mData": 'taskCode',
                      "render":function(obj){
                          return "<a href='${ctx}/orderMsg/v2_queryOrderMsg?_taskCode="+obj+"' title='查看任务信息' target='_blank'>"+obj+"</a>";
                        }
                      },
                  {
                    "mData": 'cancelStatus',
                    "render": function (obj) {
                       var cancelStatus=obj;
                       if(cancelStatus=='ok'){
                         return "正常单";
                       }else if(cancelStatus=='cancel'){
                         return "<font color=red>取消单</font>";
                       }else if(cancelStatus=='refuse'){
                         return "<font color=red>拒收单</font>";
                       }else if(cancelStatus=='change'){
                         return "<font color=red>换货单</font>";
                       }else if(cancelStatus=='outScope'){
                         return "<font color=red>超区件</font>";
                       }else if(cancelStatus=='lose'){
                         return "<font color=red>丢件单</font>";
                       }else{
                         return "";
                       }
                    }
                  },
                  {
                    "mData": 'status',
                    "render": function (obj) {
                       var status=obj;
                       if(status=='1'){
                         return "创建批次";
                       }else if(status=='2'){
                         return "创建任务";
                       }else if(status=='3'){
                         return "已拣货";
                       }else if(status=='4'){
                         return "已灯光拣选";
                       }else if(status=='5'){
                         return "已包装";
                       }else if(status=='6'){
                         return "已发货";
                       }else if(status=='9'){
                         return "待包装";
                       }else if(status=='0'){
                         return "待创建批次";
                       }else{
                         return "";
                       }
                    }
                  }
           ]
      });
    }
    
    //初始化dataTables-订单回传失败
    function initTableSendOutFail(){
      dataTables_sendOutFail=$("#table_sendOutFail").dataTable({
         "bServerSide":true,
         "sAjaxSource":'${ctx}/v2/firstPage/bindData_sendOutFail',
         "fnServerData": retrieveData_sendOutFail,
         "bFilter": false,
         "bSort": false,
         "sZeroRecords": "查询无记录！",
         "bProcessing": true,
         "oLanguage": {
             "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
          },
          "aoColumns": [ 
                  {"mData": null,
                  	 "mRender": function (data, display, row) {
	              		<c:forEach items="${customerList}" var="customer">
							if("${customer.customerCode}" == row.customerCode){
								return "${customer.customerName}";
							}
						</c:forEach>
						return "";
		           }
                  },
                  {
                    "mData": 'order.ordeno',
                    "render":function(obj){
                      return "<a href='${ctx}/orderMsg/v2_orderMsgDetail/"+obj+"' title='查看订单信息' target='_blank'>"+obj+"</a>";
                    }
                  },
                  {"mData": 'customerOrderno'},
                  {"mData": 'fromno'},
                  {"mData": 'expressNo',
                  "render":function(obj,type,full){
                  	return full.expressNo||full.ebillNo;
                  }},
                  {
                    "mData": 'billType',
                    "render": function (obj) {
                       var billType=obj;
                       if(billType=='cbill'){
                         return "普通面单";
                       }else if(billType=='ebill'){
                         return "电子面单";
                       }else{
                         return "";
                       }
                    }
                  },
                  {"mData": 'warehouseCode'},
                  {
                    "mData": 'id',
                    "render": function (obj) {
                    	var id = obj;
                    	return "<button type=\"button\" class=\"btn btn-info\" style=\"margin-left: 10px;\" onclick=\"ajaxSendOutOrdeno('"+id+"');\" id=\"send_"+id+"\">重新回传</button>";
                    }
                  }
           ]
      });
    }
    
  
	function  ajaxSendOutOrdeno(item){
		  $("#send_"+item).attr("disabled",true);
		  $.ajax({
				type : 'post',
				url : '${ctx}/orderMsg/ajaxSendOutOrdeno',
				data : 'id=' + item,
				dataType : 'json',
				success : function(data) {
				   jAlert(data.content);
				},
				error : function() {
					jAlert("获取信息错误！");
				}
			});
	  }
	//查询
	function query(){
	  
	   //验证查询条件：
	   //商家：
	   var customerCode=$("#_customerCode").val();
	   /* if(customerCode.length==0){
	      alert("请选择商家...");
	      return;
	   } */
	   
	   //日期：
	   var dataRange=$("#_dataRange").val();
	   if(dataRange.length==0){
	      alert("请选择日期范围...");
	      return;
	   }
	
	   if (dataTables_unhandle) {
	     //dataTables_unhandle.fnDestroy();
	     dataTables_unhandle.fnDraw();
   	   } else{
   	     initTableUnhandle();
   	   }
	   if (dataTables_working) {
	     //dataTables_working.fnDestroy();
	     dataTables_working.fnDraw();
   	   } else{
   	     initTableWorking();
   	   }
	   if (dataTables_handled) {
	     //dataTables_handled.fnDestroy();
	     dataTables_handled.fnDraw();
   	   } else{
   	     initTableHandled();
   	   }
	   if (dataTables_exception) {
	     //dataTables_exception.fnDestroy();
	     dataTables_exception.fnDraw();
   	   } else{
   	    initTableException();
   	   }
	   if (dataTables_sendOutFail) {
	     //dataTables_sendOutFail.fnDestroy();
	     dataTables_sendOutFail.fnDraw();
   	   } else{
   	     initTableSendOutFail();
   	   }

	   // $('.notLoad').attr('hidden','hidden');
	}
	
	
	//回调函数_待处理订单
	function retrieveData_unhandle( sSource, aoData, fnCallback ) {
	
	   //查询参数
	   var customerCode=$("#_customerCode").val();
	   aoData.push( { "name": "customerCode", "value": customerCode } );  
	    
	   var warehouseCode=$("#_warehouseCode").val();
	   aoData.push( { "name": "warehouseCode", "value": warehouseCode } );
	   
	   var dataRange=$("#_dataRange").val();
	   aoData.push( { "name": "dataRange", "value": dataRange } );
	   
	   var orderno=$("#_orderno").val();
	   aoData.push( { "name": "orderno", "value": orderno } );
	   
	   var logistics=$("#_logistics").val();
	   aoData.push( { "name": "cacode", "value": logistics } );
	   
	   $.ajax({ 
	       "type": "post",
	       "contentType": "application/json", 
	       "url": sSource,    
	       "dataType": "json",   
	       "data": JSON.stringify(aoData),
	       "success": function(resp) {  
	       			fnCallback(resp);
	       			$("#total_unhandle").html("("+resp.iTotalRecords+")");
	       		}
	   });    
	}
	
	//回调函数_作业中
	function retrieveData_working( sSource, aoData, fnCallback ) { 
	   
	   //查询参数
	   var customerCode=$("#_customerCode").val();
	   aoData.push( { "name": "customerCode", "value": customerCode } );  
	    
	   var warehouseCode=$("#_warehouseCode").val();
	   aoData.push( { "name": "warehouseCode", "value": warehouseCode } );
	   
	   var dataRange=$("#_dataRange").val();
	   aoData.push( { "name": "dataRange", "value": dataRange } );
	   
	   var orderno=$("#_orderno").val();
	   aoData.push( { "name": "orderno", "value": orderno } );
	   
	   var logistics=$("#_logistics").val();
	   aoData.push( { "name": "cacode", "value": logistics } );
	   
	   var status=$("#_status").val();
	   aoData.push( { "name": "status", "value": status } );
	    
	   $.ajax({ 
	       "type": "post",
	       "contentType": "application/json", 
	       "url": sSource,    
	       "dataType": "json",   
	       "data": JSON.stringify(aoData),
	       "success": function(resp) {  
	       			fnCallback(resp);
	       			$("#total_working").html("("+resp.iTotalRecords+")");
	       		}
	   });    
	}
	
	//回调函数_已发货
	function retrieveData_handled( sSource, aoData, fnCallback ) { 
	   
	   //查询参数
	   var customerCode=$("#_customerCode").val();
	   aoData.push( { "name": "customerCode", "value": customerCode } );  
	    
	   var warehouseCode=$("#_warehouseCode").val();
	   aoData.push( { "name": "warehouseCode", "value": warehouseCode } );
	   
	   var dataRange=$("#_dataRange").val();
	   aoData.push( { "name": "dataRange", "value": dataRange } );
	   
	   var orderno=$("#_orderno").val();
	   aoData.push( { "name": "orderno", "value": orderno } );
	    
	   var logistics=$("#_logistics").val();
	   aoData.push( { "name": "cacode", "value": logistics } );
	   
	   $.ajax({ 
	       "type": "post",
	       "contentType": "application/json", 
	       "url": sSource,    
	       "dataType": "json",   
	       "data": JSON.stringify(aoData),
	       "success": function(resp) {  
	       			fnCallback(resp);
	       			$("#total_handled").html("("+resp.iTotalRecords+")");
	       		}
	   });    
	}
	
	//回调函数_异常单
	function retrieveData_exception( sSource, aoData, fnCallback ) { 
	   
	   //查询参数
	   var customerCode=$("#_customerCode").val();
	   aoData.push( { "name": "customerCode", "value": customerCode } );  
	    
	   var warehouseCode=$("#_warehouseCode").val();
	   aoData.push( { "name": "warehouseCode", "value": warehouseCode } );
	   
	   var dataRange=$("#_dataRange").val();
	   aoData.push( { "name": "dataRange", "value": dataRange } );
	   
	   var orderno=$("#_orderno").val();
	   aoData.push( { "name": "orderno", "value": orderno } );
	   
	   var logistics=$("#_logistics").val();
	   aoData.push( { "name": "cacode", "value": logistics } );
	    
	   $.ajax({ 
	       "type": "post",
	       "contentType": "application/json", 
	       "url": sSource,    
	       "dataType": "json",   
	       "data": JSON.stringify(aoData),
	       "success": function(resp) {  
	       			fnCallback(resp);
	       			$("#total_exception").html("("+resp.iTotalRecords+")");
	       		}
	   });    
	}
	
	//回调函数_回传订单失败
	function retrieveData_sendOutFail( sSource, aoData, fnCallback ) { 
	   
	   //查询参数
	   var customerCode=$("#_customerCode").val();
	   aoData.push( { "name": "customerCode", "value": customerCode } );  
	    
	   var warehouseCode=$("#_warehouseCode").val();
	   aoData.push( { "name": "warehouseCode", "value": warehouseCode } );
	   
	   var dataRange=$("#_dataRange").val();
	   aoData.push( { "name": "dataRange", "value": dataRange } );
	   
	   var orderno=$("#_orderno").val();
	   aoData.push( { "name": "orderno", "value": orderno } );
	   
	   var logistics=$("#_logistics").val();
	   aoData.push( { "name": "cacode", "value": logistics } );
	    
	   $.ajax({ 
	       "type": "post",
	       "contentType": "application/json", 
	       "url": sSource,    
	       "dataType": "json",   
	       "data": JSON.stringify(aoData),
	       "success": function(resp) {  
	       			fnCallback(resp);
	       			$("#total_sendOutFail").html("("+resp.iTotalRecords+")");
	       		}
	   });    
	}
	//批量重接订单
	function batchReuse(){
		var tempString = "";
		$("#modalBodyOrders").html(tempString);
		   var customerCode=$("#_customerCode").val();
		   if(customerCode.length==0){
			      alert("请选择商家...");
			      return;
			 }
		   var warehouseCode=$("#_warehouseCode").val();
		   if(warehouseCode.length==0){
			      alert("请选择仓库...");
			      return;
			 }
		   //日期：
		   var dataRange=$("#_dataRange").val();
		   if(dataRange.length==0){
		      alert("请选择日期范围...");
		      return;
		   }
		   var result = confirm('是否批量重接订单！');
			if(result){
				showBg();
			   $.ajax({
					type : 'post',
					url : '${ctx}/ediOrderSource/batchReuse',
					data : 'customerCode=' + customerCode  + '&warehouseCode=' + warehouseCode + '&dataRange=' + dataRange,
					dataType : 'json',
					success : function(data) {
						closeBg();
						if(data.status=="1"){
							initTableUnhandle();
							alert(data.msg);
						}else{
							alert(data.msg);
						}
					},
					error : function() {
						closeBg();						
						alert("服务器异常，请重试");
					}
				}); 
			}
	}
	
	function exportExcel(){
		if($("#_customerCode").val().length == 0){
			alert("请选择商家...") ; 
			return ;
		}
		if($("#_warehouseCode").val().length == 0){
			alert("请选择仓库...") ; 
			return ;
		}
		$("#queryForm").attr("action","${ctx}/v2/firstPage/exportExcel");
		$("#queryForm").submit();
	}
	
	function add(){
		var name;
		var value;
		var j = 0;
		var s = new Array();
		for(i = 0; i < 10; i++){
			name = "#_expressNo" + i;
			value = $(name).val().trim();
			if(value != ''){
				s[j] = value;
				j = j + 1;
			}
		}
		
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/firstPage/addExpressNo',
			data : {
				"expressNo[]":s
			},
			dataType : 'json',
			success : function(data) {
			   alert(data.content);
			   for(i = 0; i < 10; i++){
				   $("#_expressNo" + i).val('');
			   }
			   window.location.href = "${ctx}/v2/firstPage/toFirstPage";
			},
			error : function() {
				alert("添加京东快递单号失败！");
				for(i = 0; i < 10; i++){
					   $("#_expressNo" + i).val('');
				   }
				window.location.href = "${ctx}/v2/firstPage/toFirstPage";
			}
		});
		
		
	}
	
	function check(obj){
		var id = obj.id;
		var j = id.substring(id.length-1,id.length);
		var value = $(obj).val();
		var value2;
		var name;
		for(i = 0; i < 10; i++){
			if(i != j){
				name = "#_expressNo" + i;
				value2 = $(name).val();
				if(value == value2){
					alert("填入单号重复,请核对后重新填入.");
					$(obj).val('');
					$(obj).focus();
					return;
				}
			}
		}
		
		if(j == 9){
			name = "#_expressNo0";
		}else{
			name = Number(j) + Number(1);
			name = "#_expressNo" + name;
		}
		$(name).focus();
		
	}
	
	function ajaxAreaGroup2(item,id) {
	    $("#"+id).html('');
		var customerCode=item.value;
		if(customerCode==''){
		  return false;
		}
		
		
		if(customerCode == 'YNBY'){
			$("#add").show();
		}else{
			$("#add").hide();
		}
		
		$.ajax({
				type : 'post',
				url : path+'/areaGroup/ajaxAreaGroup',
				data : 'customerCode=' + customerCode,
				dataType : 'json',
				success : function(data) {
				  var tempString="";
				  tempString+="<option value=''></option>";
					if (data.status == "1") {
						$.each(data.content,function(i){
						    tempString+="<option value="+data.content[i].groupCode+">"+data.content[i].groupName;
						});
					}else if (data.status == "2") {
						$.each(data.content.restAreaGroupDtos,function(i){
						    tempString+="<option value="+data.content.restAreaGroupDtos[i].areagroupCode+">"+data.content.restAreaGroupDtos[i].areagroupName;
						});
					} else {
						alert(data.content);
					}
	                  $("#"+id).html(tempString);
	                  $("#"+id).trigger("chosen:updated");
				},
				error : function() {
					alert("获取信息错误！");
				}
			});
	}
	
</script>
</head>

<body>
<div id="fullbg"></div>
<div id="dialog">
	<div>
		<img src="${ctx }/static/022.gif"></img>
	</div>
</div>

<section class="content">
    <!-- 查询条件  start-->
   	<div class="row">
	<div class="col-md-12">
			<!-- Primary box -->
			<div class="box box-solid box-primary" >
			    
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
				</div>
				
				<div class="box-body">
				    <form class="form-search" id="queryForm" method="post" >
				    <!-- 第一行 -->
					<div class="form-group row">
					
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 商家： </span> 
								<select data-placeholder="请选择..." class="form-control searchSelect" id="_customerCode" name="_customerCode" onchange="ajaxAreaGroup2(this,'_warehouseCode')">
									<option value=""></option>
									<c:forEach items="${customerList}" var="customer">
										<option value="${customer.customerCode}"
											<c:if test="${customerCode eq customer.customerCode}">selected=selected</c:if>>${customer.customerName}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 仓库： </span> 
								<select class="form-control span3" id="_warehouseCode" name="_warehouseCode">
									<option value=""></option>
									<c:forEach items="${warehouseList}" var="warehouse">
										<option value="${warehouse.groupCode}" >${warehouse.groupName}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 订单编号： </span> 
								<input type="text" class="form-control" id="_orderno" name="_orderno">
							</div>
						</div>
						
						<div class="col-sm-3">
								<div class="input-textgroup col-sm-12">
								<span class="input-group-text">订单状态:</span>
								<!--  TODO 修改批次状态值 -->
								<!-- 批次状态 (1.已创建批次 2.已创建任务 3.已拣货 4.已包装  5.已发货) -->
								<select  class="form-control" id="_status" name="_status" >
								        <option value="" <c:if test="${param._status eq ''}">selected="selected"</c:if>>全选</option>
								        <option value="1" <c:if test="${param._status eq '1'}">selected="selected"</c:if>>创建批次</option>
								        <option value="2" <c:if test="${param._status eq '2'}">selected="selected"</c:if>>创建任务</option>
								        <option value="3" <c:if test="${param._status eq '3'}">selected="selected"</c:if>>已拣货</option>
								        <option value="4" <c:if test="${param._status eq '4'}">selected="selected"</c:if>>已灯光拣选</option>
								        <option value="5" <c:if test="${param._status eq '5'}">selected="selected"</c:if>>已包装</option>
								        <option value="9" <c:if test="${param._status eq '9'}">selected="selected"</c:if>>待包装</option>
								</select> 
								</div>
						</div>
						
					</div>

                    <!-- 第二行 -->
					<div class=" form-group row">

						<div class="col-sm-6">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 日期范围： </span>

								<div class="input-group">
									<div class="input-group-addon">
										<i class="fa fa-calendar"></i>
									</div>
									<input type="text" class="form-control pull-right" id="_dataRange" name="_dataRange" value="${param._fromDate}"/>
								</div>
								
							</div>
						</div>
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 快递公司： </span> 
								<select class="form-control span3" id="_logistics" name="_logistics">
									<option value=""></option>
									<c:forEach items="${logisticsList}" var="logistics">
										<option value="${logistics.companyCode}" >${logistics.companyName}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						
					</div>
					 <!-- 第三行 -->
					<div class=" form-group row">
						<div class="col-sm-1" style="text-align: right;">
								<button class="btn btn-primary" type="button" onclick="query();">搜索</button>
								<a id="add" href='#express' class='btn btn-primary' role='button' data-toggle='modal' >添加京东单号</a>
								<!-- begin remove 去掉批量重新接单按钮和导出不可处理订单按钮 20160713 by zhangweize -->
								<!--  
								<%
								 ShiroUser user = (ShiroUser) SecurityUtils.getSubject().getPrincipal();
								 if(user.username.equals("admin") || user.username.equals("dingchengli") || user.username.equals("hujinhua") || user.username.equals("chengdiandian") || user.username.equals("zhangcanhui")){ 
								 %>
								<button class="btn btn-primary" type="button" onclick="batchReuse();">批量重接订单</button>
								<%} %>
								
								<button class="btn btn-info" type="button" onclick="exportExcel();">导出不可处理订单</button>
								-->
								<!-- begin remove 去掉批量重新接单按钮和导出不可处理订单按钮 20160713 by zhangweize -->
						</div>
						<div class="col-sm-3">
							<!-- <label class="notLoad"><font color="red">为缓解双十一系统压力，数据查询请手动点击【搜索】！</font></label> -->
							<img src="${ctx}/static/elevenInfo.png" height="40px">
						</div>
					</div>
					</form>
				</div>

			</div>

	 </div>
	</div>
    <!-- 查询条件 end -->
  
    <!-- 查询结果 start -->
	<div class="form-group row" >
	<div class="col-md-12">
		
		<!-- TAB start -->
		<div class="nav-tabs-custom">
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#tab_1" data-toggle="tab">待处理<span id="total_unhandle"></span></a></li>
                    <li><a href="#tab_2" data-toggle="tab">作业中<span id="total_working"></span></a></li>
                    <li><a href="#tab_3" data-toggle="tab">已发货<span id="total_handled"></span></a></li>
                    <li><a href="#tab_4" data-toggle="tab">异常单<span id="total_exception"></span></a></li>
                    <li><a href="#tab_5" data-toggle="tab">订单回传异常<span id="total_sendOutFail"></span></a></li>
                </ul>
                
                <div class="tab-content">
                
                    <div class="tab-pane active" id="tab_1">
                         <!-- 待处理订单 start --> 
                         <div class="box">
							 <div class="box-header"></div>
							 <div class="box-body table-responsive">
							     <table id="table_unhandle" class="table table-bordered table-striped">
							         <thead>
							             <tr>
							                <th style="width: 60px;">商家</th>
							                <th style="width: 20px;">仓库</th>
										    <th style="width: 100px;">能容订单号</th>
										    <th style="width: 80px;">来源店铺</th>
										    <th style="width: 50px;">收货人</th>
										    <th style="width: 50px;">目的地</th>
										    <th style="width: 50px;">快递公司</th>
										    <th style="width: 30px;">可处理</th>
										    <th style="width: 60px;">审单时间 </th>
										    <th style="width: 100px;">查询操作</th>
							             </tr>
							         </thead>
							         <tfoot>
							             <tr>
							                <th style="width: 60px;">商家</th>
							                <th style="width: 20px;">仓库</th>
										    <th style="width: 100px;">能容订单号</th>
										    <th style="width: 80px;">来源店铺</th>
										    <th style="width: 50px;">收货人</th>
										    <th style="width: 50px;">目的地</th>
										    <th style="width: 50px;">快递公司</th>
										    <th style="width: 30px;">可处理</th>
										    <th style="width: 60px;">审单时间 </th>
										    <th style="width: 100px;">查询操作</th>
							             </tr>
							         </tfoot>
							     </table>
							 </div>
						 </div>
						 <!-- 待处理订单 end -->
                    </div>
                    
                    <div class="tab-pane" id="tab_2">
                        <!-- 作业中订单 start --> 
                        <div class="box">
						 <div class="box-header"></div>
						 <div class="box-body table-responsive">
						     <table id="table_working" class="table table-bordered table-striped">
						         <thead>
						             <tr>
					                 	<th style="width: 50px;">商家</th>
									    <th style="width: 100px;">能容订单号</th>
									    <th style="width: 100px;">商家订单号</th>
									    <th style="width: 100px;">来源订单号</th>
									    <th style="width: 100px;">快递单号</th>
									    <th style="width: 100px;">运单类型</th>
									    <th style="width: 50px;">仓库</th>
									    <th style="width: 100px;">作业批次</th>
									    <th style="width: 100px;">作业任务</th>
									    <th style="width: 100px;">订单状态</th>
									    <th style="width: 100px;">作业状态</th>
						             </tr>
						         </thead>
						         <tfoot>
						             <tr>
						                <th style="width: 50px;">商家</th>
									    <th style="width: 100px;">能容订单号</th>
									    <th style="width: 100px;">商家订单号</th>
									    <th style="width: 100px;">来源订单号</th>
									    <th style="width: 100px;">快递单号</th>
									    <th style="width: 100px;">运单类型</th>
									    <th style="width: 50px;">仓库</th>
									    <th style="width: 100px;">作业批次</th>
									    <th style="width: 100px;">作业任务</th>
									    <th style="width: 100px;">订单状态</th>
									    <th style="width: 100px;">作业状态</th>
						             </tr>
						         </tfoot>
						     </table>
						 </div>
					 </div>
					 <!-- 作业中订单 end -->
                   </div>
                   
                   <div class="tab-pane" id="tab_3">
                        <!-- 已发货订单 start --> 
                        <div class="box">
						 <div class="box-header"></div>
						 <div class="box-body table-responsive">
						     <table id="table_handled" class="table table-bordered table-striped">
						         <thead>
						             <tr>
					                 	<th style="width: 50px;">商家</th>
									    <th style="width: 100px;">能容订单号</th>
									    <th style="width: 100px;">商家订单号</th>
									    <th style="width: 100px;">来源店铺</th>
									    <th style="width: 100px;">来源订单号</th>
									    <th style="width: 100px;">快递单号</th>
									    <th style="width: 100px;">运单类型</th>
									    <th style="width: 50px;">仓库</th>
									    <th style="width: 100px;">作业批次号</th>
									    <th style="width: 100px;">收件人</th>
									    <th style="width: 100px;">订单状态</th>
									    <th style="width: 100px;">作业状态</th>
						             </tr>
						         </thead>
						         <tfoot>
						             <tr>
						                <th style="width: 50px;">商家</th>
									    <th style="width: 100px;">能容订单号</th>
									    <th style="width: 100px;">商家订单号</th>
									    <th style="width: 100px;">来源店铺</th>
									    <th style="width: 100px;">来源订单号</th>
									    <th style="width: 100px;">快递单号</th>
									    <th style="width: 100px;">运单类型</th>
									    <th style="width: 50px;">仓库</th>
									    <th style="width: 100px;">作业批次</th>
									    <th style="width: 100px;">收件人</th>
									    <th style="width: 100px;">订单状态</th>
									    <th style="width: 100px;">作业状态</th>
						             </tr>
						         </tfoot>
						     </table>
						 </div>
					 </div>
					 <!-- 已发货订单 end -->
                   </div>
                   
                   
                   <div class="tab-pane" id="tab_4">
                        <!-- 异常单 start --> 
                        <div class="box">
						 <div class="box-header"></div>
						 <div class="box-body table-responsive">
						     <table id="table_exception" class="table table-bordered table-striped">
						         <thead>
						             <tr>
					                 	<th style="width: 50px;">商家</th>
									    <th style="width: 100px;">能容订单号</th>
									    <th style="width: 100px;">来源店铺</th>
									    <th style="width: 100px;">商家订单号</th>
									    <th style="width: 100px;">来源订单号</th>
									    <th style="width: 100px;">快递单号</th>
									    <th style="width: 100px;">运单类型</th>
									    <th style="width: 50px;">仓库</th>
									    <th style="width: 100px;">作业批次</th>
									    <th style="width: 100px;">作业任务</th>
									    <th style="width: 100px;">订单状态</th>
									    <th style="width: 100px;">作业状态</th>
						             </tr>
						         </thead>
						         <tfoot>
						             <tr>
						                <th style="width: 50px;">商家</th>
									    <th style="width: 100px;">能容订单号</th>
									    <th style="width: 100px;">来源店铺</th>
									    <th style="width: 100px;">商家订单号</th>
									    <th style="width: 100px;">来源订单号</th>
									    <th style="width: 100px;">快递单号</th>
									    <th style="width: 100px;">运单类型</th>
									    <th style="width: 50px;">仓库</th>
									    <th style="width: 100px;">作业批次</th>
									    <th style="width: 100px;">作业任务</th>
									    <th style="width: 100px;">订单状态</th>
									    <th style="width: 100px;">作业状态</th>
						             </tr>
						         </tfoot>
						     </table>
						 </div>
					 </div>
					 <!-- 异常单 end -->
                   </div>
                   
                   <div class="tab-pane" id="tab_5">
                        <!-- 异常单 start --> 
                        <div class="box">
						 <div class="box-header"></div>
						 <div class="box-body table-responsive">
						     <table id="table_sendOutFail" class="table table-bordered table-striped">
						         <thead>
						             <tr>
					                 	<th style="width: 50px;">商家</th>
									    <th style="width: 100px;">能容订单号</th>
									    <th style="width: 100px;">商家订单号</th>
									    <th style="width: 100px;">来源订单号</th>
									    <th style="width: 100px;">快递单号</th>
									    <th style="width: 100px;">运单类型</th>
									    <th style="width: 50px;">仓库</th>
									    <th style="width: 100px;">操作</th>
						             </tr>
						         </thead>
						         <tfoot>
						             <tr>
						                <th style="width: 50px;">商家</th>
									    <th style="width: 100px;">能容订单号</th>
									    <th style="width: 100px;">商家订单号</th>
									    <th style="width: 100px;">来源订单号</th>
									    <th style="width: 100px;">快递单号</th>
									    <th style="width: 100px;">运单类型</th>
									    <th style="width: 50px;">仓库</th>
									    <th style="width: 100px;">操作</th>
						             </tr>
						         </tfoot>
						     </table>
						 </div>
					 </div>
					 <!-- 异常单 end -->
                   </div>
                    
              </div>
            </div>
            <!-- TAB end -->
			
	</div>
	</div>
	<!-- 查询结果 end -->
	
	<!-- 弹出窗体-商品详情 start  -->
	<div id="ordersDetail" class="modal fade">
		<div class="modal-dialog" style="width: 60%;">
			<div class="modal-content">
			
				<div class="modal-body">
					<div class="box box-solid box-primary">
			      		<div class="box-header"><span class="box-title">订单详细信息</span></div>
						<div class="box-body">
							<table class="table table-striped table-bordered table-condensed" id="modalBodyOrders"></table>
						</div>
					</div>
				</div>
				
			</div>	
		</div>
	</div>
	<!-- 弹出窗体-商品详情 end  -->
	
	<!-- 弹出窗体-订单详情 start  -->
	<div id="orderItemsDetail" class="modal fade">
		<div class="modal-dialog" style="width: 60%;">
			<div class="modal-content">
			
				<div class="modal-body">
					<div class="box box-solid box-primary">
			      		<div class="box-header"><span class="box-title">订单详细信息</span></div>
						<div class="box-body">
							<table class="table table-striped table-bordered table-condensed" id="modalBodyItems"></table>
						</div>
					</div>
				</div>
				
			</div>	
		</div>
	</div>
	<!-- 弹出窗体-订单详情 end  -->
	
	<div id="express" class="modal fade">
		<div class="modal-dialog" style="width: 40%;">
			<div class="modal-content">
				<div class="modal-body">
					<div class="box box-solid box-primary">
			      		<div class="box-header"><span class="box-title">添加京东单号</span></div>
			      		<div class="box-body" align="center">
								<input type="text" class="form-control span" id="_expressNo0" name="_expressNo0" maxlength=30 onchange="check(this)"><br/>
				      			<input type="text" class="form-control span" id="_expressNo1" name="_expressNo1" maxlength=30 onchange="check(this)"><br/>
				      			<input type="text" class="form-control span" id="_expressNo2" name="_expressNo2" maxlength=30 onchange="check(this)"><br/>
				      			<input type="text" class="form-control span" id="_expressNo3" name="_expressNo3" maxlength=30 onchange="check(this)"><br/>
				      			<input type="text" class="form-control span" id="_expressNo4" name="_expressNo4" maxlength=30 onchange="check(this)"><br/>
				      			<input type="text" class="form-control span" id="_expressNo5" name="_expressNo5" maxlength=30 onchange="check(this)"><br/>
				      			<input type="text" class="form-control span" id="_expressNo6" name="_expressNo6" maxlength=30 onchange="check(this)"><br/>
				      			<input type="text" class="form-control span" id="_expressNo7" name="_expressNo7" maxlength=30 onchange="check(this)"><br/>
				      			<input type="text" class="form-control span" id="_expressNo8" name="_expressNo8" maxlength=30 onchange="check(this)"><br/>
				      			<input type="text" class="form-control span" id="_expressNo9" name="_expressNo9" maxlength=30 onchange="check(this)"><br/>
			      			<div>
								<button class="btn btn-primary" type="button" onclick="add();">确认添加</button>
							</div>
						</div>
					</div>
				</div>
			</div>	
		</div>
	</div>
	
	
	</section>
</body>
</html>